#include <iostream>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>
#include "log.hpp"
#include "Socket.hpp"
#include "inetAddr.hpp"
#include "Protocol.hpp"

void GetDataFromStdin(int *x, int *y, char *oper)
{
    std::cout << "Please Enter x: ";
    std::cin >> *x;
    std::cout << "Please Enter y: ";
    std::cin >> *y;
    std::cout << "Please Enter oper: ";
    std::cin >> *oper;
}

using namespace LogModule;
int main()
{
    // std::string ip("192.168.8.16");
    std::string ip("127.0.0.1");
    uint16_t port = 8080;
    InetAddr peer(port, ip);

    // 1、创建套接字
    std::shared_ptr<Socket> client = std::make_shared<UdpSocket>();
    client->BuiltUdpClientSocket(peer);

    // 2、创建协议对象
    std::unique_ptr<Protocol> protocol = std::make_unique<Protocol>();
    // 2、得到一组完整的数据，并传输给服务器
    while (true)
    {
        int x, y;
        char oper;
        GetDataFromStdin(&x, &y, &oper);
        std::string req_str = protocol->BuiltOneGroupData(x, y, oper);
        client->Send(req_str);

        std::string _wait_queue;
        Response res;
        protocol->GetResponse(client, _wait_queue, res);
    }

    return 0;
}